package com.example.workspace.utils;

import com.example.workspace.dto.PositionDto;

import java.awt.*;
import java.awt.event.InputEvent;
import java.util.List;
import java.util.Random;

public class MouseUtils {
    /**
     * 移动鼠标，并且点击
     * @param delay 延迟多少秒
     */
    public static void mouseMoveAndClick(Robot robot, List<PositionDto> positionList,int delay){

        try {
            Random random = new Random();

            for (PositionDto p : positionList) {
                int nextInt = random.nextInt(400);

                robot.mouseMove(p.getX(),p.getY());
                robot.delay(300+nextInt);
                robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
                robot.delay(500+nextInt);
                robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
                Thread.sleep(1000 * delay);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
